//
//  USOurInfoViewController.m
//  us
//
//  Created by devkarry on 2025/5/6.
//

#import "USOurInfoViewController.h"
#import <SafariServices/SafariServices.h>

@interface USOurInfoViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) NSArray *list;

@end

@implementation USOurInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"us信息和策略";
    
    DTItem *item0 = [DTItem itemWithTitle:@"隐私政策" image:nil tag:0 identifier:nil handle:nil];
    
    DTItem *item1 = [DTItem itemWithTitle:@"用户协议" image:nil tag:1 identifier:nil handle:nil];
    
    self.list = @[item0,item1];
    
    self.us_tableView.dataSource = self;
    self.us_tableView.delegate = self;
    
    
    
}

#pragma mark - <UITableViewDelegate,UITableViewDataSource>
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.list.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [UITableViewCell us_defaultCell];
    
    DTItem *item = self.list[indexPath.row];
    
    cell.textLabel.text = item.title;
    
    [cell us_setDefaultArrow];
    
    return cell;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [USFeedbackTool impactSoft];
    DTItem *item = self.list[indexPath.row];
    if (item.tag == 0) {
        
        SFSafariViewController *vc = [[SFSafariViewController alloc]initWithURL:[NSURL URLWithString:@"http://www.emmo.club/us/privacyAgreement_cn.html"]];
        [self presentViewController:vc animated:YES completion:nil];
        
            
    }else if (item.tag == 1){
        SFSafariViewController *vc = [[SFSafariViewController alloc]initWithURL:[NSURL URLWithString:@"http://www.emmo.club/us/userAgreement_cn.html"]];
        [self presentViewController:vc animated:YES completion:nil];
        
    }    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return [UITableViewCell us_defaultCellRowHeight];
    
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{

    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 40)];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
    [btn setTitle:@"备案号：苏ICP备2021017560号-8A" forState:0];
    [btn addTarget:self action:@selector(gotoICPAction:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:btn];
    
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(12);
        make.right.mas_offset(-12);
        make.centerY.mas_equalTo(view);
    }];
    
    return view;
    
}

- (void)gotoICPAction:(id)sender{
    [USFeedbackTool impactSoft];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://beian.miit.gov.cn/"] options:@{} completionHandler:nil];
}



@end
